<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
	</head>
	<body>
		<div id="app">
			{{num}}
			<br />
			<input type="text" v-model="num" />
			<br />
			{{message}}
			<br />
			{{result}}
		</div>
		
		<script>
			var app = Vue.createApp({
				data(){
					return {
						message: "Hello World!",
						num: 10,
						result: ''
					}
				},
				// 函数方法
				methods:{
					sleep(numberMillis){
						var now = new Date();
						var exitTime = now.getTime() + numberMillis;
						while(true){
							now = new Date();
							if(now.getTime() > exitTime){
								return
							}
						}
					}
				},
				// 数据监听
				watch:{
					num(newVal, oldVal){
						console.log(newVal + "旧值" + oldVal)
						this.message = "监听到数据变化！新值：" + newVal + "\n旧值：" + oldVal
						
						// 1.新建一个worker线程
						var worker = new Worker("long_task.js")
						// 2.注册worker发回数据的处理
						worker.onmessage = (event)=>this.result = event.data
						// 2.向worker发送数据
						worker.postMessage(newVal)
						

					}
				}
			}).mount("#app")
		</script>
	</body>
</html>
